<?php

namespace Xiaoc\Api;

use PhalApi\Api;

/**
 * Xiaoc普通商品
 *
 * @author: zhy <zhy302813@163.com> 2017-8-19
 */
class Goods extends Common
{
    public function getRules()
    {
        return array(
            'goodslist' => array(
                'cid' => array('name' => 'cid', 'require' => true, 'default' => 0, 'desc' => '分类ID'),
                'sort_type' => array('name' => 'sort_type', 'require' => true, 'default' => 0, 'desc' => '排序方式0综合1销量2价格'),
                'sort' => array('name' => 'sort', 'require' => true, 'default' => 0, 'desc' => '排序方式0降序1升序'),
                'page' => array('name' => 'page', 'require' => true, 'default' => 1, 'desc' => '当前页数'),
                'keywords' => array('name' => 'keywords', 'desc' => '搜索关键词'),
                'pmin' => array('name' => 'pmin', 'desc' => '搜索价格最小值'),
                'pmax' => array('name' => 'pmax', 'desc' => '搜索价格最大值'),
                'type' => array('name' => 'type', 'desc' => '商品类型:0全部商品10精品20新品30热销40促销', 'default' => 0)
            ),
            'goodsinfo' => array(
                'goods_id' => array('name' => 'goods_id', 'require' => true, 'min' => 1, 'default' => 0, 'desc' => '商品ID'),
                'token' => array('name' => 'token', 'desc' => '用户Token')
            ),
            'subcate' => array(
                'cat_id' => array('name' => 'cat_id', 'require' => true, 'min' => 1, 'default' => 0, 'desc' => '父级分类ID')
            ),
            'goodscomment' => array(
                'goods_id' => array('name' => 'goods_id', 'require' => true, 'min' => 1, 'default' => 0, 'desc' => '商品ID'),
                'page' => array('name' => 'page', 'require' => true, 'default' => 1, 'desc' => '当前页数')
            ),
            'collect' => array(
                'goods_id' => array('name' => 'goods_id', 'require' => true, 'min' => 1, 'default' => 0, 'desc' => '商品ID'),
                'token' => array('name' => 'token', 'require' => true, 'desc' => '用户Token'),
            ),
            'guest_goods' => array(
                'limit' => array('name' => 'limit', 'default' => 4, 'desc' => '查询条数'),
                'token' => array('name' => 'token', 'require' => true, 'desc' => '用户Token'),
            ),
            'get_goods_attr_num' => array(
                'goods_id' => array('name' => 'goods_id', 'desc' => '商品ID', 'require' => true),
                'ids' => array('name' => 'ids', 'desc' => '属性ID以逗号隔开', 'require' => true),
            ),
            'get_goods_attr' => array(
                'goods_id' => array('name' => 'goods_id', 'desc' => '商品ID', 'require' => true),
            ),
            'get_goods_desc' => array(
                'goods_id' => array('name' => 'goods_id', 'desc' => '商品ID', 'require' => true),
            ),
            'importList' => array(
                'page' => array('name' => 'page', 'desc' => '页码', 'require' => true, 'default' => 0),
            )
        );
    }

    /**
     * 商品列表
     * @desc 商品列表
     * @return int goods_id ID
     * @return string goods_name 名称
     * @return float shop_price 价格
     * @return string goods_thumb (host+)图片路径
     * @return float market_price 市场价
     * @return string goods_brief 商品简介（副标题）
     * @return string goods_product_tag 商品标签（多个以,分割）
     * @return int warn_number 库存预警值
     * @return boolean has_more 是否有下一页
     * @return int page 当前页数
     */
    public function goodslist()
    {
        if ($this->sort_type == 1) {
            $sort = "sales_volume";
        } else if ($this->sort_type == 2) {
            $sort = "shop_price";
        } else {
            $sort = "goods_id";
        }
        if ($this->sort == 1) {
            $desc = "desc";
        } else {
            $desc = "asc";
        }

        $limit = ($this->page - 1) * 10;
        $type = array();
        switch ($this->type) {
            case 0:
                $where = array('review_status > ?' => 2, 'goods_number > ?' => 0, 'is_on_sale = ?' => 1);
                break;
            case 10:
                $where = array('review_status > ?' => 2, 'goods_number > ?' => 0, 'is_on_sale = ?' => 1,'is_best = ?' => 1);
                break;
            case 20:
                $where = array('review_status > ?' => 2, 'goods_number > ?' => 0, 'is_on_sale = ?' => 1,'is_new = ?' => 1);
                break;
            case 30:
                $where = array('review_status > ?' => 2, 'goods_number > ?' => 0, 'is_on_sale = ?' => 1,'is_hot = ?' => 1);
                break;
            case 40:
                $where = array('review_status > ?' => 2, 'goods_number > ?' => 0, 'is_on_sale = ?' => 1,'is_promote = ?' => 1);
                break;
        }
        if ($this->keywords) {
            $where['goods_name LIKE ?'] = '%' . $this->keywords . '%';
        }
        if ($this->cid) {
            $cat_ids = $this->notorm->category->select('cat_id')->where(array('parent_id' => $this->cid))->fetchRows();
            if ($cat_ids) {
                foreach ($cat_ids as $val) {
                    $arr[] = $val['cat_id'];
                }
                $where['cat_id'] = $arr;
            } else {
                $where['cat_id'] = $this->cid;
            }
        }
        if ($this->pmin > 0 && $this->pmax && $this->pmin < $this->pmax) {
            $where['shop_price > ?'] = $this->pmin;
            $where['shop_price < ?'] = $this->pmax;
        }

        $data['has_more'] = true;
        $data['page'] = $this->page;

        $data['list'] = \PhalApi\DI()
            ->notorm
            ->goods
            ->select('goods_id,goods_name,shop_price,market_price,goods_brief,goods_thumb,goods_product_tag,warn_number')
            ->where($where)
            ->order($sort . ' ' . $desc)
            ->limit($limit, 10);

        $more = \PhalApi\DI()
            ->notorm
            ->goods
            ->select('goods_id')
            ->where($where)
            ->order($sort . ' ' . $desc)
            ->limit($this->page * 10, 1)
            ->fetchRows();
        if (!count($more)) {
            $data['has_more'] = false;
        }
        return $data;
    }

    /**
     * 商品详情页
     * @desc 商品详情页
     * @return int goods_id ID
     * @return string goods_name 名称
     * @return float shop_price 价格
     * @return int click_count 点击浏览量
     * @return string goods_thumb (host+)图片路径
     * @return object images 商品相册
     * @return float market_price 市场价
     * @return string goods_brief 商品简介（副标题）
     * @return string goods_product_tag 商品标签（多个以,分割）
     * @return int warn_number 库存预警值
     * @return string goods_desc 详情(pc)
     * @return string desc_mobile 详情(手机)
     * @return object actinfo 活动明细
     * @return boolean is_try 参与试用
     * @return boolean is_crowd 参与众筹
     * @return int act_id 活动ID
     * @return int commentnum 评价数
     * @return string goodpercent 好评百分比
     * @return object storeinfo 店铺信息
     * @return boolean is_collect 是否收藏
     */
    public function goodsinfo()
    {
        $goods_id = $this->goods_id;
        $data['goodsinfo'] = \PhalApi\DI()
            ->notorm
            ->goods
            ->select('goods_id,goods_name,shop_price,market_price,goods_brief,goods_thumb,goods_product_tag,warn_number,goods_desc,desc_mobile,click_count,user_id,goods_number')
            ->where(array('review_status > ?' => 2, 'goods_number > ?' => 0, 'goods_id' => $goods_id))
            ->fetchOne();
        $images = \PhalApi\DI()
            ->notorm
            ->goods_gallery
            ->select('thumb_url')
            ->where(array('goods_id' => $goods_id))
            ->order('img_id desc')
            ->fetchAll();
        if (count($data['goodsinfo']) > 0) {
            //添加点击量
            \PhalApi\DI()->notorm->goods->where('goods_id', $goods_id)->update(array('click_count' => $data['goodsinfo']['click_count'] + 1));
        }
        $data['images'] = array();
        if (count($images) > 0) {
            foreach ($images as $vo) {
                $data['images'][] = $vo['thumb_url'];
            }
        } else {
            if (isset($data['goodsinfo']['goods_thumb'])) {
                $data['images'][] = $data['goodsinfo']['goods_thumb'];
            }
        }
        //促销活动查看
        $crowd = \PhalApi\DI()
            ->notorm
            ->goods_activity
            ->select('act_id,ext_info')
            ->where(array('review_status' => 3, 'start_time < ?' => gmtime(), 'end_time > ?' => gmtime(), 'act_type' => 1, 'goods_id' => $goods_id))
            ->order('act_id desc')
            ->fetchOne();
        $try = \PhalApi\DI()
            ->notorm
            ->goods_activity
            ->select('act_id')
            ->where(array('review_status' => 3, 'start_time < ?' => gmtime(), 'end_time > ?' => gmtime(), 'act_type' => 7, 'goods_id' => $goods_id))
            ->order('act_id desc')
            ->fetchOne();
        if ($crowd) {
            $data['actinfo'][] = array('is_crowd' => true, 'act_id' => $crowd['act_id'], 'ext_info' => unserialize($crowd['ext_info']));
        } else {
            $data['actinfo'][] = array('is_crowd' => false, 'act_id' => 0);
        }
        if ($try) {
            $data['actinfo'][] = array('is_try' => true, 'act_id' => $try['act_id']);
        } else {
            $data['actinfo'][] = array('is_try' => false, 'act_id' => 0);
        }
        $prefix = \PhalApi\DI()->config->get('dbs.tables.__default__.prefix');
        $sql = 'select a.attr_id, a.attr_name, a.attr_group, a.is_linked, a.attr_type ,g.goods_attr_id, g.attr_value, g.attr_price, g.attr_img_flie, g.attr_img_site, g.attr_checked, g.attr_sort from ';
        $sql .= $prefix . 'goods_attr as g left join ' . $prefix . 'attribute as a on a.attr_id = g.attr_id where g.goods_id =' . $goods_id . ' and a.attr_type = 1 order by a.sort_order, a.attr_id, g.goods_attr_id';
        $attr = \PhalApi\DI()->notorm->goods_attr->queryAll($sql, array());
        $arr = array();
        foreach ($attr as $row) {
            $row['attr_value'] = str_replace("\n", '<br />', $row['attr_value']);
            //$row['img_flie'] = get_has_attr_info($row['attr_id'], $row['attr_value'], $row['attr_img_flie'], 0);  //规格图片

            $arr['spe'][$row['attr_id']]['attr_type'] = $row['attr_type'];
            $arr['spe'][$row['attr_id']]['name'] = $row['attr_name'];
            $attr_checked = isset($arr['spe'][$row['attr_id']]['values']) > 0 ? 0 : 1;
            $arr['spe'][$row['attr_id']]['values'][] = array(
                'label' => $row['attr_value'],
                'checked' => $attr_checked,
                'attr_sort' => $row['attr_sort'],
                'price' => $row['attr_price'],
                'id' => $row['goods_attr_id']
            );
            $arr['spe'][$row['attr_id']]['values'] = get_array_sort($arr['spe'][$row['attr_id']]['values'], 'attr_sort');
        }
        if (isset($arr['spe']) && count($arr['spe']) > 0) {
            foreach ($arr['spe'] as $key => $vo) {
                $rs[] = $vo;
                unset($arr['spe'][$key]);
            }
            $arr['spe'] = $rs;
        }

        //评价
        $comment = \PhalApi\DI()
            ->notorm
            ->comment
            ->select('count(*) as cnum')
            ->where(array('id_value' => $goods_id, 'status' => 1, 'parent_id' => 0))
            ->fetchOne();
        $data['commentnum'] = $comment['cnum'];
        if ($comment['cnum'] != 0) {
            $rank = \PhalApi\DI()
                ->notorm
                ->comment
                ->select('count(*) as cnum')
                ->where(array('id_value' => $goods_id, 'status' => 1, 'parent_id' => 0, 'comment_rank > ? ' => 3))
                ->fetchOne();
            $data['goodpercent'] = round(($rank['cnum'] / $comment['cnum']) * 100, 1);
        } else {
            $data['goodpercent'] = '100%';
        }
        $data['attr'] = $arr;

        //店铺信息
        if ($data['goodsinfo']['user_id'] == 0) {//自营店铺
            $store['name'] = '校创官方自营店';
            $store['logo'] = "";
            $store['id'] = 0;
            $store['shopNameSuffix'] = '自营店';
            $store['score'] = array('desc' => 5.0, 'serve' => 5.0, 'speed' => 5.0);
        } else {
            $storeinfo = \PhalApi\DI()
                ->notorm
                ->merchants_shop_information
                ->select('rz_shopName,shopNameSuffix')
                ->where(array('user_id' => $data['goodsinfo']['user_id']))
                ->fetchOne();
            $store['name'] = $storeinfo['rz_shopName'];
            $store['shopNameSuffix'] = $storeinfo['shopNameSuffix'];
            $shopinfo = \PhalApi\DI()
                ->notorm
                ->seller_shopinfo
                ->select('logo_thumb')
                ->where(array('ru_id' => $data['goodsinfo']['user_id']))
                ->fetchOne();
            $store['logo'] = isset($shopinfo['logo_thumb']) ? substr($shopinfo['logo_thumb'], 3) : '';
            $store['id'] = $data['goodsinfo']['user_id'];
            $score = \PhalApi\DI()
                ->notorm
                ->comment_seller
                ->select('desc_rank,service_rank,delivery_rank')
                ->where(array('ru_id' => $data['goodsinfo']['user_id']))
                ->fetchAll();
            $desc = $serve = $speed = $i = 0;
            foreach ($score as $vo) {
                $desc += $vo['desc_rank'];
                $serve += $vo['service_rank'];
                $speed += $vo['delivery_rank'];
                $i++;
            }
            if ($i > 0) {
                $store['score'] = array('desc' => round($desc / $i, 1), 'serve' => round($serve / $i, 1), 'speed' => round($speed / $i, 1));
            } else {
                $store['score'] = array('desc' => 5.0, 'serve' => 5.0, 'speed' => 5.0);
            }
        }
        $data['is_collect'] = false;
        if ($this->token) {
            $userinfo = $this->get_users_info($this->token);
            if ($userinfo) {
                $collect = \PhalApi\DI()
                    ->notorm
                    ->collect_goods
                    ->select('rec_id')
                    ->where(array('user_id' => $userinfo['user_id'], 'goods_id' => $goods_id))
                    ->fetchOne();
                if (isset($collect['rec_id']) && $collect['rec_id']) {
                    $data['is_collect'] = true;
                }
            }
            //统计足迹
            $user_goods_id = $this->di->cache->get($userinfo['user_id'] . 'goods');
            $user_goods_ids = array();
            if ($user_goods_id) {
                foreach ($user_goods_id as $value) {
                    $user_goods_ids[] = $value['goods_id'];
                }
            }
            if (!in_array($goods_id, $user_goods_ids)) {
                $goods_info = $data['goodsinfo'];
                if ($goods_info) {
                    $val['goods_id'] = $goods_id;
                    $val['time'] = time();
                    $val['goods_name'] = $goods_info['goods_name'];
                    $val['shop_price'] = $goods_info['shop_price'];
                    $val['market_price'] = $goods_info['market_price'];
                    $val['goods_thumb'] = $goods_info['goods_thumb'];
                    $val['goods_product_tag'] = $goods_info['goods_product_tag'];
                    $user_goods_id[] = $val;
                    $this->di->cache->delete($userinfo['user_id'] . 'goods');
                    $this->di->cache->set($userinfo['user_id'] . 'goods', $user_goods_id, 30 * 86400);
                }
            }
        }
        $data['storeinfo'] = $store;
        return $data;
    }

    /**
     * 商品评论
     * @desc 评论列表
     * @return int comment_id ID
     * @return string user_name 用户名
     * @return string user_head 用户头像
     * @return string content 评论内容
     * @return string goods_attr 商品属性
     * @return int comment_rank 评论星级
     * @return int add_time 评价时间
     * @return int user_id 用户ID
     * @return boolean has_more 是否有下页
     * @return int page 当前页数
     */
    public function goodscomment()
    {
        $where['comment.status'] = 1;
        $where['comment.id_value'] = $this->goods_id;
        $where['comment.comment_type'] = 0;
        $where['LIMIT'] = array($this->limitStart, $this->limitEnd);
        $where['ORDER'] = array('comment.comment_id' => 'DESC');
        $join['[>]users'] = array('user_id');
        $join['[>]order_goods'] = array('id_value' => 'goods_id');
        $field = array('comment.comment_id', 'comment.user_name', 'comment.content', 'comment.comment_rank', 'comment.add_time', 'users.user_picture(user_head)', 'order_goods.goods_attr');
        $list = $this->di->medoo->select('comment', $join, $field, $where);
        $count = 0;
        if ($list) {
            foreach ($list as $key => $value) {
                if ($value['add_time']) {
                    $list[$key]['add_time'] = time_format($value['add_time'], 'Y-m-d');
                } else {
                    $list[$key]['add_time'] = '';
                }
            }
            unset($where['LIMIT']);
            unset($where['ORDER']);
            $count = $this->medoo->count('comment', $join, 'comment.comment_id', $where);
        } else {
            $list = array();
        }
        $data['list'] = $list;
        $data['has_more'] = $this->HasMore($count);
        return $data;
    }

    /**
     * 商品分类
     * @desc 所有一级分类
     * @return int cat_id ID
     * @return string cat_name 名称
     * @return string touch_icon (host+)图片路径
     */
    public function goodscate()
    {
        $data = \PhalApi\DI()
            ->notorm
            ->category
            ->select('cat_id, cat_name, touch_icon')
            ->where(array('parent_id' => 0, 'is_show' => 1))
            ->order('sort_order asc,cat_id desc')
            ->fetchAll();
        return $data;
    }

    /**
     * 商品分类
     * @desc 获取子分类
     * @return int cat_id ID
     * @return string cat_name 名称
     * @return string touch_icon (host+)图片路径
     */
    public function subcate()
    {
        $cat_id = $this->cat_id;
        $data = \PhalApi\DI()
            ->notorm
            ->category
            ->select('cat_id, cat_name, touch_icon')
            ->where(array('parent_id' => $cat_id, 'is_show' => 1))
            ->order('sort_order asc,cat_id desc')
            ->fetchAll();
        return $data;
    }

    /**
     * 商品收藏
     * @desc 收藏商品与取消
     * @return string msg 操作信息
     * @return boolean is_collect 是否收藏
     */
    public function collect()
    {
        $userinfo = $this->check_login($this->token);
        $goods_id = trim($this->goods_id, ',');
        $data['is_collect'] = false;
        $where['goods_id'] = explode(',', $goods_id);
        $rec_ids = $this->medoo->select('collect_goods', 'rec_id', $where);
        if ($rec_ids) {
            $res = $this->medoo->delete('collect_goods', $where);
            if ($res) {
                $data['msg'] = '已取消收藏！';
                $data['is_collect'] = false;
            } else {
                $data['msg'] = '取消失败！';
                $data['is_collect'] = true;
            }
        } else {
            foreach ($where['goods_id'] as $value) {
                $arr[] = array(
                    'user_id' => $userinfo['user_id'],
                    'goods_id' => $value,
                );
            }
            $res = $this->medoo->insert('collect_goods', $arr);
            if ($res) {
                $data['msg'] = '收藏成功！';
                $data['is_collect'] = true;
            } else {
                $data['msg'] = '收藏失败！';
                $data['is_collect'] = false;
            }
        }
        return $data;
    }

    /**
     * 猜您喜欢
     * @desc 猜你喜欢
     * @return array
     */
    public function guest_goods()
    {
        $limit = $this->limit ? $this->limit : 4;
        $userinfo = $this->check_login($this->token);
        $user_id = $userinfo['user_id'];
        $prefix = \PhalApi\DI()->config->get('dbs.tables.__default__.prefix');

        $order_idArr = $finished_goods = $link_cats = array();

        $sql = 'SELECT order_id FROM ' . $prefix . 'order_info  WHERE user_id = \'' . $user_id . '\' ORDER BY order_id DESC LIMIT 5';
        $order_arr = \PhalApi\DI()->notorm->order_info->queryAll($sql, array());
        $finished_goodsStr = '';
        if ($order_arr) {
            foreach ($order_arr as $key => $val) {
                $order_idArr[] = $val['order_id'];
            }

            $order_str = db_create_in($order_idArr, 'og.order_id');
            $sql = 'SELECT g.goods_id, g.cat_id FROM ' . $prefix . 'order_goods' . ' AS og ' . 'LEFT JOIN ' . $prefix . 'goods AS g ON g.goods_id = og.goods_id ' . 'WHERE ' . $order_str . ' GROUP BY g.goods_id DESC';
            $cat_All = \PhalApi\DI()->notorm->order_goods->queryAll($sql, array());

            foreach ($cat_All as $kk => $vv) {
                $finished_goodsStr .= '\'' . $vv['goods_id'] . '\',';
                $link_cats[] = $vv['cat_id'];
            }

            $finished_goodsStr = substr($finished_goodsStr, 0, -1);
            $link_cats = array_unique($link_cats);
            $link_cats_str = db_create_in($link_cats, 'cat_id');
            $sql = 'SELECT goods_id, goods_name, goods_thumb, shop_price,sales_volume,goods_product_tag,goods_brief FROM ' . $prefix . 'goods WHERE ' . $link_cats_str .
                ' AND goods_id NOT IN (' . $finished_goodsStr . ') AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0 ORDER BY sales_volume DESC  LIMIT 8';
            $query = \PhalApi\DI()->notorm->goods->queryAll($sql, array());
        }

        if ((empty($guess_goods) || (count($guess_goods) < $limit))) {
            $guess_goods = array();
            $sql = 'SELECT goods_id, goods_name, goods_thumb, shop_price, user_id, sales_volume,market_price,goods_brief,goods_product_tag FROM ' . $prefix .
                'goods WHERE  (sales_volume > 0 OR is_hot = 1) AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0 ORDER BY sales_volume DESC LIMIT ' . $limit;
            $query = \PhalApi\DI()->notorm->goods->queryAll($sql, array());
        }

        foreach ($query as $row) {
            $guess_goods[] = $row;
        }
        return $guess_goods;
    }

    /**
     * 根据属性获取库存
     * @desc 根据属性获取库存
     * @return int num 库存
     */
    public function get_goods_attr_num()
    {
        $goods_id = $this->goods_id;
        $ids = explode(',', trim($this->ids, ','));
        sort($ids);
        $ids = trim(implode($ids, '|'));
        $where['goods_id'] = $goods_id;
        $where['goods_attr'] = $ids;
        $data['num'] = 0;
        $number = $this->medoo->get('products', 'product_number', $where);
        if ($number) {
            $data['num'] = $number;
        }
        return $data;
    }

    /**
     * 根据商品ID获取规格
     * @desc 根据商品ID获取规格
     * @return array 请看商品详情规格字段
     */
    public function get_goods_attr()
    {
        $goods_id = $this->goods_id;
        $prefix = get_table_prefix();
        $sql = 'select a.attr_id, a.attr_name, a.attr_group, a.is_linked, a.attr_type ,g.goods_attr_id, g.attr_value, g.attr_price, g.attr_img_flie, g.attr_img_site, g.attr_checked, g.attr_sort from ';
        $sql .= $prefix . 'goods_attr as g left join ' . $prefix . 'attribute as a on a.attr_id = g.attr_id where g.goods_id =' . $goods_id . ' and a.attr_type = 1 order by a.sort_order, a.attr_id, g.goods_attr_id';
        $attr = $this->di->notorm->goods_attr->queryAll($sql, array());
        $arr = array();
        if ($attr) {
            foreach ($attr as $row) {
                $row['attr_value'] = str_replace("\n", '<br />', $row['attr_value']);
                $arr['spe'][$row['attr_id']]['attr_type'] = $row['attr_type'];
                $arr['spe'][$row['attr_id']]['name'] = $row['attr_name'];
                $attr_checked = isset($arr['spe'][$row['attr_id']]['values']) > 0 ? 0 : 1;
                $arr['spe'][$row['attr_id']]['values'][] = array(
                    'label' => $row['attr_value'],
                    'checked' => $attr_checked,
                    'attr_sort' => $row['attr_sort'],
                    'price' => $row['attr_price'],
                    'id' => $row['goods_attr_id']
                );
                $arr['spe'][$row['attr_id']]['values'] = get_array_sort($arr['spe'][$row['attr_id']]['values'], 'attr_sort');
            }
            if (isset($arr['spe']) && count($arr['spe']) > 0) {
                foreach ($arr['spe'] as $key => $vo) {
                    $rs[] = $vo;
                    unset($arr['spe'][$key]);
                }
                $arr['spe'] = $rs;
            }
        }
        return $arr;
    }

    /**
     * 商品描述
     * @desc 商品描述
     * @return mixed
     */
    public function get_goods_desc()
    {
        $goods_id = $this->goods_id;
        $goods_info = $this->medoo->get('goods', array('desc_mobile', 'user_id'), array('goods_id' => $goods_id));
        //店铺信息
        if ($goods_info['user_id'] == 0) {//自营店铺
            $store['name'] = '3S官方自营店铺';
            $store['logo'] = "";
            $store['id'] = 0;
            $store['shopNameSuffix'] = '自营店';
            $store['score'] = array('desc' => 5.0, 'serve' => 5.0, 'speed' => 5.0);
        } else {
            $storeinfo = \PhalApi\DI()
                ->notorm
                ->merchants_shop_information
                ->select('rz_shopName,shopNameSuffix')
                ->where(array('user_id' => $goods_info['user_id']))
                ->fetchOne();
            $store['name'] = $storeinfo['rz_shopName'];
            $store['shopNameSuffix'] = $storeinfo['shopNameSuffix'];
            $shopinfo = \PhalApi\DI()
                ->notorm
                ->seller_shopinfo
                ->select('logo_thumb')
                ->where(array('ru_id' => $goods_info['user_id']))
                ->fetchOne();
            $store['logo'] = isset($shopinfo['logo_thumb']) ? substr($shopinfo['logo_thumb'], 3) : '';
            $store['id'] = $goods_info['user_id'];
            $score = \PhalApi\DI()
                ->notorm
                ->comment_seller
                ->select('desc_rank,service_rank,delivery_rank')
                ->where(array('ru_id' => $goods_info['user_id']))
                ->fetchAll();
            $desc = $serve = $speed = $i = 0;
            foreach ($score as $vo) {
                $desc += $vo['desc_rank'];
                $serve += $vo['service_rank'];
                $speed += $vo['delivery_rank'];
                $i++;
            }
            if ($i > 0) {
                $store['score'] = array('desc' => round($desc / $i, 1), 'serve' => round($serve / $i, 1), 'speed' => round($speed / $i, 1));
            } else {
                $store['score'] = array('desc' => 5.0, 'serve' => 5.0, 'speed' => 5.0);
            }
        }
        $data['goods_desc'] = $goods_info['desc_mobile'];
        $data['store'] = $store;
        return $data;
    }

    /**
     * 特惠商品列表
     * @desc 特惠商品列表
     * @return mixed
     */
    public function importList()
    {
        $model = new \Xiaoc\Model\Goods();
        $list = $model->importList($this->page);
        return $list;
    }
}
